<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
$(function(){
	var page=1;
	$("#accordion").accordion({
		heightStyle: "content"
	});
	$("#viewMore").click(function(){
		page++;
		$.ajax({
			type:"post",
			url:"gallery.do",
			data:"mode=listByUser&uid=${sessionScope.mvo.uId}&page="+page,
			success:function(jsonData){
				var tag="";
				console.log(jsonData);
				$.each(jsonData.list,function(i,list){
					tag+="<h3><img src=/img/thumb_gal/"+list.thumbImgName+"></h3>";
					tag+="<div><p><b>title : "+list.title+"</b></p><p><img src=/img/upload_gal/"+list.orgImgName+" width=90%></p>";
					tag+="<p>"+list.contents+"</p><p style='font-size: 9px;'>"+list.w_date+"  추천수: "+list.wow;
					tag+="  <a href=gallery.do?mode=delete&no="+list.no+"&img="+list.orgImgName+"&thumb="+list.thumbImgName+">삭제</a>";
					tag+="  <a href=gallery.do?mode=view&page=update&no="+list.no+"&uid=${sessionScope.mvo.uId}	>수정</a></p></div>";
				});
				$("#accordion").append(tag).accordion('destroy').accordion({heightStyle:'content'});
			}
		});
	});
});
</script>
<c:if test="${sessionScope.mvo==null }">
<jsp:forward page="../index.jsp"></jsp:forward>
</c:if>
<div id="main_write">
<form action="gallery.do" method="post" id="writeForm" enctype="multipart/form-data">
<input type="hidden" name="mode" value="write">
<table>
<tr>
	<td>사진</td>
	<td>
		<input type="file" name="uploadImg" id="main_uploadImg"><br>
		3MB 이하로 업로드해주세요
	</td>
</tr>
<tr>
	<td>제목</td>
	<td><input type="text" name="title" id="main_title" size="60"></td>
</tr>
<tr>
	<td>내용</td>
	<td><textarea name="contents" id="main_content" cols="60" rows="5"></textarea></td>
</tr>
<tr>
<td>Category</td>
	<td>
		<select name="category" id="category">
			<option value="">------</option>
			<option value="practice">습작</option>
			<option value="series">연작</option>
			<option value="art">작품</option>
		</select>
	</td>
</tr>
<tr align="right">
	<td colspan="2"><input type="button" id="writeBtn" value="확인"></td>
</tr>
</table>
<input type="hidden" name="wow" value="0">
</form>
</div>
<div id="friendList">
	<table>
		<tr>
			<td><img src="/img/profile/${sessionScope.mvo.proImg }"></td>
			<td>
			<table>
				<tr><td><b>${sessionScope.mvo.id }</b></td></tr>
				<tr><td>nickname : ${sessionScope.mvo.nickname }</td></tr>
				<tr><td>level : ${sessionScope.mvo.level }</td></tr>
				<tr><td><pre>${sessionScope.mvo.info }</pre></td></tr>
			</table>
			</td>
		</tr>
	</table>
</div>
<div id="myGallery">
	<div id="accordion">
		<c:forEach items="${requestScope.list }" var="list">
			<h3><img src="/img/thumb_gal/${list.thumbImgName }"></h3>
			<div>
				<p><img src="/img/upload_gal/${list.orgImgName }" width="90%"></p>
				<c:choose>
				<c:when test="${list.category=='practice' }">
					<p>category : <b>습작 갤러리</b></p>
				</c:when>
				<c:when test="${list.category=='series' }">
					<p>category : <b>연작 갤러리</b></p>
				</c:when>
				<c:otherwise>
					<p>category : <b>작품 갤러리</b></p>
				</c:otherwise>
				</c:choose>
				<p><b>title : ${list.title }</b></p>
				<p>${list.contents }</p>
				<p style="font-size: 9px;">${list.w_date }  추천수:${list.wow }  
				<a href="gallery.do?mode=delete&no=${list.no }&img=${list.orgImgName}&thumb=${list.thumbImgName}">삭제</a>  
				<a href="gallery.do?mode=view&page=update&no=${list.no }&uid=${sessionScope.mvo.uId}">수정</a></p>
			</div>
		</c:forEach>
	</div>
	<div id="viewMore" align="center" style="border:1px; border-style:solid; border-color:white; width:150px;height:30px; margin: auto;">더 보기</div>
</div>
<script type="text/javascript">
$("#writeBtn").click(function(){
	if($("#main_uploadImg").val()==""){
		alert("사진을 올려주세요!");
		return;
	}
	if($("#category").val()==""){
		alert("카테고리를 선택해주세요!!");
		return;
	}
	if($("#main_uploadImg")[0].files[0].size>3145728){
		alert("3MB 이하로 업로드해주세요!!");
		$("#main_uploadImg").val("");
		return;
	}
	$("#writeForm").submit();
});
</script>